package common{
	
	import mx.collections.ArrayCollection;

	public class LsMapUtil{
		//客户平均停电时间
		public static const _personalize1:int = 1;
		//购售电及综合线损率
		public static const _personalize2:int = 2;
		//购售电及综合线损率
		public static const _RANKCOLOR:Array = ['#6d0606','#9a1616','#c9530c','#b95132','#dd7042','#c88a2f','#c3934b','#ddb16f'] ;
		//图例
		private static var _legend:ArrayCollection = null;

		public static function legend():ArrayCollection {
			if(_legend == null){
				_legend = new ArrayCollection();
				var color1:Object = new Object();
				color1.color = "#00B050";
				color1.text = "<2小时，国际先进";
				var color2:Object = new Object();
				color2.color = "#00DFF3";
				color2.text = "<5小时，南网十二五目标值";
				var color3:Object = new Object();
				color3.color = "#FFFF00";
				color3.text = "<=8小时，南网2013年目标值";
				var color4:Object = new Object();
				color4.color = "#F0760A";
				color4.text = ">8小时，未达到南网2013年目标值";
				_legend.addItem(color1);
				_legend.addItem(color2);
				_legend.addItem(color3);
				_legend.addItem(color4);
			}
			return _legend;
		}
		
		public static function color(value:Number):String{
			var color:String = "";
			if(value<2){
				color = "#00B050";
			} else if(value>=2 && value <5){
				color = "#00DFF3";
			} else if(value>=5 && value <=8){
				color = "#FFFF00";
			} else if( value >8){
				color = "#F0760A";
			}
			return color;
		}
		
		public static function rankColor(value:Number):String{
			var color:String = "";
			if(value <= _RANKCOLOR.length){
				color = _RANKCOLOR[value-1];
			} else{
				color = _RANKCOLOR[_RANKCOLOR.length-1];
			}
			return color;
		}
		
		public static function getGaugeXML(config:Object):XML{
			var xml:XML = <anychart>
							<margin all="0" />
							<settings>
								<animation enabled="true" />
							</settings>
							<gauges>
								<gauge>
									<chart_settings>
										<title enabled="true" position="bottom" padding="-6">
											<text>{config.dwmc}</text>
<font family="Microsoft Yahei" color="#FFFFFF" />
										</title>
										<chart_background enabled="false" />
									</chart_settings>
									<linear orientation="Vertical">
										<margin left="0" />
										<axis enabled="true" size='20'>
											<scale minimum="0" maximum={config.data*1.2||"100"} />
											<scale_bar enabled="false" />
											<scale_line enabled="false" />
											<major_tickmark enabled="false" />
											<minor_tickmark enabled="false" />
											<labels enabled="false" />
										</axis>
										<pointers>
											<label enabled="true">
												<format></format>
<font family="Microsoft Yahei" color="#FFFFFF" size="12" bold="false"/>
												<position anchor="Top" halign="Center"/>
												<background enabled="false" >
													<effects enabled="false" />
												</background>
											</label>
											<pointer type="Tank" value={config.data||"0"}   color="green">
												<animation enabled="true" start_time="0" duration="0.8" interpolation_type="Circular" />
											</pointer>
										</pointers>
									</linear>
								</gauge>
							</gauges>
						</anychart>;
			xml.gauges[0].gauge[0].linear[0].pointers[0].label[0].format = "{%Value}{numDecimals:0," +
				"thousandsSeparator:}"+ (config.tb!=null?("(" +
					(Number(config.tb)<0?"▼":"▲") +
					config.tb + "%)"):"");
			
			return xml;
		}
		private static function getXML(config:Object):XML{
			var xml:XML = <anychart>
							<margin all="0"/>
							<settings>
								<animation enabled="true" />
							</settings>
							<charts>
							<chart plot_type="CategorizedVertical">
								<data_plot_settings default_series_type="Bar" shape_type="Bar">
									<bar_series style="Silver" point_padding="0" group_padding="1">
										<label_settings enabled="true">
											<position anchor="CenterTop" halign="Center" valign="Top" padding="0"/> 
<font family="Microsoft Yahei" color="#FFFFFF" size="11"  bold="false"/>
										    	<format>{"{%YValue}{numDecimals:0,thousandsSeparator:}"} </format>
										 </label_settings>
										<tooltip_settings enabled="true">
<font family="Microsoft Yahei" bold="false" size="12" />
											<format>{"{%SeriesName}:{%YValue}{numDecimals:2}"}(亿千瓦时)</format>
										</tooltip_settings>
									</bar_series>
								</data_plot_settings>
								<chart_settings>
									<chart_background enabled="false">
										<border enabled="false" />
										<fill type="Gradient"  color="#000000" opacity="0"/>
									</chart_background>
									<data_plot_background enabled="false" />
									<title enabled="false" />
									<axes>
										<x_axis enabled="true">
											<labels enabled="false" />
											<major_tickmark enabled="false" />
											<minor_tickmark enabled="false" />
											<major_grid enabled="false" />
  											<minor_grid enabled="false" />
											<title padding="0" >
<font family="Microsoft Yahei" color={config.color} />
												<text>{(config.dwmc||"") + ("\n" + config.xsl + "%")}</text>
											</title>
										</x_axis>
										<y_axis enabled="false">
											<labels enabled="false" />
 											<major_tickmark enabled="false" />
    											<minor_tickmark enabled="false" />
											<major_grid enabled="false" />
  											<minor_grid enabled="false" />
											<scale maximum_offset={config.maximumOffset||"0.1"}  maximum={config.maximum||"6500"} minimum="0"/>  
										</y_axis>
									</axes>
								</chart_settings>
								<data>
								</data>
								<styles>
									<label_style name="labelLeft">
										<position anchor="RightTop" halign="left" valign="Top" padding="0"/> 
<font family="Microsoft Yahei" color="#FFFFFF" size="11"  bold="false"/>
										<format>{"{%YValue}{numDecimals:0,thousandsSeparator:}"} </format>
									</label_style>
									<label_style name="labelRight">
										<position anchor="LeftTop" halign="Right" valign="Top" padding="0"/> 
<font family="Microsoft Yahei" color="#FFFFFF" size="11"  bold="false"/>
										<format>{"{%YValue}{numDecimals:0,thousandsSeparator:}"} </format>
									</label_style>
								</styles>
							</chart>
						</charts>
					</anychart>;
			return xml;
		}
		
		public static function parseBarXml(config:Object,data:Object):XML {
			var wdbm:String = config.wdbm;
			var zbbm:Array = config.zbbm;
			var zbmc:Array = config.zbmc;
			var xmlStr:String="";
			if(data['rn'] >=6 && (data['gddw'] != '099900' && data['gddw'] != '019900')){
				 config.color = "#000000";
			}else{
				 config.color = "#FFFFFF";
			}
			if(data["gdl"]<=1000){
				config.maximum=data["gdl"]+300
			}else if(data["gdl"]<=3000){
				config.maximum=data["gdl"]+500
			}else{
				config.maximum=data["gdl"]+1100
			}
			var barXml:XML = getXML(config);
			var seriesColor:Array= config.seriesColor || ['#4AA0F8','#FFFFFF'];
			var value:Number = 0;
			for(var i:int=0;i<zbbm.length;i++){
				xmlStr='<series name="'+zbmc[i]+'" type="Bar" color="'+seriesColor[i]+'">'; 
				/*if(data[zbbm[i]] != null){
					value = data[zbbm[i]];
					xmlStr+='<point name="'+data[wdbm]+'" y="'+value+'" />';
				}else{
					xmlStr+='<point />';
				}*/
				if(data[zbbm[i]] != null){
					value = data[zbbm[i]];
				}
				xmlStr+='<point name="'+data[wdbm]+'" y="'+value+'" >';
				if(i==0){
					xmlStr+='<label style="labelLeft"/>';
				}else{
					xmlStr+='<label style="labelRight"/>';
				}
				xmlStr+='</point>';
				xmlStr+='</series>';
				barXml.charts[0].chart[0].data[0].appendChild(new XML(xmlStr));
			}
			return   barXml;
		}
		
		
		
	}
}